<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Regex Composer</title>

    <style type="text/css">
        <!--
        .style1 {
            font-family: "Courier New", Courier, monospace
        }

        -->
    </style>
</head>
<body>
<p>A RegexComposer is a <a href="monitors.html#composers">composer</a> allows for regular expressions to be used in conjunction with making lists of components that match that regular expression.</p>
<div class="source">
<pre>
MutablePicoContainer pico = new DefaultPicoContainer(new ComposingMonitor(new RegexComposer()));
pico.addComponent("apple1", "Braeburn");
pico.addComponent("apple2", "Granny Smith");
pico.addComponent("plum", "Victoria");
List apples = (List) pico.getComponent("apple[1-9]");
assertEquals("[Braeburn, Granny Smith]", apples.toString());
</pre>
</div>
<p>The above example is fed the regular expression in the getComponent(..) invocation, which may be in practical.  Here is one where the parameter names of the injectee are used for correlation purposes </p>
<div class="source">
<pre>
public static class NeedsApples {
    private List&lt;String> apples; 
    public NeedsApples(List&lt;String> apples) {  // correlate param name to regex below
        this.apples = apples;
    }
}

public static class NeedsPlums {
    private List&lt;String> plums;
    public NeedsPlums(List&lt;String> plums) {  // correlate param name to regex below
        this.plums = plums;
    }
}

....

MutablePicoContainer pico = new DefaultPicoContainer(
        new ComposingMonitor(new RegexComposer("apple[1-9]", "apples"), new RegexComposer("plum*", "plums")));
pico.addComponent("apple1", "Braeburn")
        .addComponent("apple2", "Granny Smith")
        .addComponent("plumV", "Victoria");
pico.as(USE_NAMES).addComponent(NeedsApples.class)
        .as(USE_NAMES).addComponent(NeedsPlums.class);

assertEquals("[Braeburn, Granny Smith]", pico.getComponent(NeedsApples.class).apples.toString());

assertEquals("[Victoria]", pico.getComponent(NeedsPlums.class).plums.toString());	
</pre>
</div>
</body>
</html>